# coding=utf-8

from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from utils.enums import Struct
import logging



class WelcomePage(webapp.RequestHandler):
    def __init__(self):
        self.template_file = 'templates/welcome.html'
        logging.info('constructor')
        self.struct = Struct()
        self.struct.style_css = ['welcome.css', 'headers/header.css']
        self.struct.logo = 'Welcome to the first page'
        self.struct.href_login = users.create_login_url('/')
        self.struct.href_logout = users.create_logout_url('/')
        self.struct.user = users.get_current_user()
        self.struct.title = '™ ' + (self.struct.user
                                          and self.struct.user.nickname()
                                          or '%username%') + ' !'


    def get(self):
#        template_file = os.path.join(os.path.dirname(__file__), 'templates/main.html')
        if(users.get_current_user()):
            self.redirect('/main')
        else:
            self.response.out.write(template.render(self.template_file, self.struct._compile()))

